﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YJKWndrStatisticsExcel.AreaTable.StatisticControler;

namespace YJKWndrStatisticsExcel.AreaTable.Forms
{
	public partial class EstateSuiteAreaStatisticalForm : System.Windows.Forms.Form
	{
		public EstateSuiteAreaStatisticalForm(List<string> floorNameList, List<EstateSuiteAreaStatisticalData> data)
		{
			this.m_Data = data;
			this.InitializeComponent();
			this.InitializeDGVColumns(floorNameList);
		}

		private void InitializeDGVColumns(List<string> floorNameList)
		{
			List<DataGridViewTextBoxColumn> list = new List<DataGridViewTextBoxColumn>();
			this.AddColumn("Column1", "编号", 40, ref list);
			this.AddColumn("Column2", "套型", 65, ref list);
			this.AddColumn("Column3", "室内使用面积", 85, ref list);
			this.AddColumn("Column4", "套内墙体面积", 85, ref list);
			this.AddColumn("Column5", "阳台面积", 65, ref list);
			this.AddColumn("Column6", "套内建筑面积", 85, ref list);
			this.AddColumn("Column7", "分摊面积", 65, ref list);
			this.AddColumn("Column8", "建筑面积(含阳台)", 110, ref list);
			for (int i = 0; i < floorNameList.Count; i++)
			{
				string name = "Column" + (i + 9).ToString();
				string text = floorNameList[i];
				this.AddColumn(name, text, 50, ref list);
			}
			string name2 = "Column" + (floorNameList.Count + 9).ToString();
			this.AddColumn(name2, "合计", 50, ref list);
			foreach (DataGridViewTextBoxColumn dataGridViewColumn in list)
			{
				this.DGVTable.Columns.Add(dataGridViewColumn);
			}
		}

		private void AddColumn(string name, string text, int width, ref List<DataGridViewTextBoxColumn> columnList)
		{
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn.HeaderText = text;
			dataGridViewTextBoxColumn.Name = name;
			dataGridViewTextBoxColumn.ReadOnly = true;
			dataGridViewTextBoxColumn.Width = width;
			columnList.Add(dataGridViewTextBoxColumn);
		}

		private void StatisticalResultForm_Load(object sender, EventArgs e)
		{
			this.AddItems();
		}

		private void AddItems()
		{
			for (int i = 0; i < this.m_Data.Count; i++)
			{
				DataGridViewRow dataGridViewRow = new DataGridViewRow();
				dataGridViewRow.DefaultCellStyle.BackColor = this.DGVTable.BackgroundColor;
				foreach (string val in this.m_Data[i].ToStrList())
				{
					this.AddTextBoxCell(dataGridViewRow, val);
				}
				this.DGVTable.Rows.Add(dataGridViewRow);
			}
		}

		private void AddTextBoxCell(DataGridViewRow row, string val)
		{
			DataGridViewTextBoxCell dataGridViewTextBoxCell = new DataGridViewTextBoxCell();
			dataGridViewTextBoxCell.Value = val;
			row.Cells.Add(dataGridViewTextBoxCell);
		}

		private List<EstateSuiteAreaStatisticalData> m_Data;
	}
}
